home *** CD-ROM | disk | FTP | other *** search
- Path: access1.digex.net!not-for-mail
- From: ell@access1.digex.net (Ell)
- Newsgroups: comp.object,comp.lang.c++
- Subject: Re: A design question
- Followup-To: comp.object,comp.lang.c++
- Date: 27 Feb 1996 05:20:59 GMT
- Organization: The Universe
- Message-ID: <4gu4br$bmc@news4.digex.net>
- References: <1996Feb22.234825.18755@dcs.warwick.ac.uk>
- NNTP-Posting-Host: access1.digex.net
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Robert C. Martin (rmartin@oma.com) wrote:
- : > miro@dcs.warwick.ac.uk (Miroslav J Walker) writes:
- : > I'm trying to model input from a user being processed over a
- : > series of steps. Input is parsed, put into a queue and then
- : > interpreted on a timer. My question is how to model the idea
- : > of it being the same bit of data (essentially) taking on
- : > several forms as it proceeds along the 'pipeline' of
- : > processing.
- : >
-
- : Richard Berman <sts@crl.com> writes:
- : >> Of course, a state table might do the trick as well.
-
- : Indeed. And there is a very nice pattern in the "Design Patterns"
- : book that describes the way in which a state machine can be
- : implemented to do just what Miroslav is asking. The pattern is called
- : "State".
- :
- : Consider the following:
- :
- : class MyParcel; /fwd declare.
- :
- : // this class is the abstract representation of the state of the
- : // parcel of data. It defines functions which respond to all the
- : // events that a parcel may experience.
- :
- : class ParcelState
- : {
- : public:
- : // the events that occur along the processing chain.
- : virtual void Event1(MyParcel&) = 0;
- : virtual void Event2(MyParcel&) = 0;
- : };
- :
- : // This is the parcel itself. It also defines functions which respond
- : // to all its events. However, these functions simply delegate to the
- : // contained state object.
- :
- : class MyParcel
- : {
- : public:
- : MyParcel();
- : void Event1() {itsState->Event1(*this);}
- : void Event2() {itsState->Event2(*this);}
- : private:
- : ParcelState* itsState;
- : };
-
- I'm wondering if the above class MyParcel shouldn't publicly inherit from
- ParcelState?
-
- Elliott
-